﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Threading.Tasks;

namespace Sino.CapacityCloud.Repositories.Models
{

    public class SmsCode
    {

        [Key()]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public string SmsId { get; set; }

        public string PhoneNumber { get; set; }

        public string Code { get; set; }

        public DateTime CreationTime { get; set; }

        public int StatusCode { get; set; }

        public DateTime FailureTime { get; set; }

        public DateTime? ApproveTime { get; set; }

        public string Remarks { get; set; }

        [NotMapped]
        public bool IsValid
        {
            get
            {
                return this.FailureTime > DateTime.Now;
            }
        }

        public SmsCode()
        {
            this.SmsId = Guid.NewGuid().ToString();
            this.CreationTime = DateTime.Now;
            this.FailureTime = this.CreationTime + TimeSpan.FromMinutes(2);
        }

        public SmsCode(TimeSpan failureTime)
        {
            this.CreationTime = DateTime.Now;
            this.FailureTime = this.CreationTime + failureTime;
        }

    }

}